package com.gitee.wsl.net.client

import android.annotation.SuppressLint
import android.content.Context
import okhttp3.internal.tls.OkHostnameVerifier
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
import javax.net.ssl.X509TrustManager

class CustomCertManagerImpl(b: Boolean=true, param: Boolean=false) : CustomCertManager {

    var appInForeground: Boolean=false

    override fun close() {
        TODO("Not yet implemented")
    }

    override fun hostnameVerifier(okHostnameVerifier: OkHostnameVerifier): OkHostnameVerifier? {
        return null
    }

    override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {
        TODO("Not yet implemented")
    }

    override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
        TODO("Not yet implemented")
    }

    override fun getAcceptedIssuers(): Array<X509Certificate> {
        TODO("Not yet implemented")
    }
}

interface CustomCertManager:X509TrustManager,AutoCloseable{
   fun hostnameVerifier(okHostnameVerifier: OkHostnameVerifier): OkHostnameVerifier?
}

class TrustAllCerts : CustomCertManager {
    override fun close() {
    }

    override fun hostnameVerifier(okHostnameVerifier: OkHostnameVerifier): OkHostnameVerifier? {
       return null
    }

    @SuppressLint("TrustAllX509TrustManager")
    @Throws(CertificateException::class)
    override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
    }

    @SuppressLint("TrustAllX509TrustManager")
    @Throws(CertificateException::class)
    override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
    }

    override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray()

    companion object{
        var INSTANCE: TrustAllCerts = TrustAllCerts();
    }
}